<?php
namespace app\common\controller;
use think\Controller;
use think\Db;

class Homebase extends Controller
{
   public function _initialize(){
   		if(!session('userinfo')){
   			 $this->redirect('/index/login');
   		}   		
   		$url = strtolower($_SERVER['REQUEST_URI']);
   		$url = Db::name('auth_rule')->where('name',$url)->find();
   		if($url){
   			$group_id = session('userinfo')['group_id'];
   			if($group_id != 1){
    			$group = Db::name('auth_group')->where('id',$group_id)->where('status',1)->find();
	   			if(!$group){
	   				echo '<script>alert("您当前用户分组不存在");</script>';die;
	   			}
	   			$rules = explode(',',$group['rules']);
	   			if(!in_array($url['id'],$rules)){
	   				$this->error("您没有权限浏览此项内容");
	   				echo '<script>alert("您没有权限浏览此项内容");</script>';die;
	   			}		
   			}
   		}
         if (time()-session('userinfo.outtime')>300) {
            session('userinfo',null);
            if (session('userinfo.group_id')==2) {
               $this->redirect('/index/login');
            }else{
               $this->redirect('/index/login/adminlogin');
            }
            
         }else{
            session('userinfo.outtime',time());
         }
   }
}
